// console.log('1');
$(function () {
    // fQuit()
    getUser()
})
// 获取用户的基本信息
function getUser() {
    $.ajax({
        type: "get",
        url: "/my/userinfo",
        success: function (res) {
            console.log(res);
            if (res.status != 0) return layui.layer.msg(res.message)
            renderAvatar(res.data)
        }
    });
}
// 渲染用户头像
function renderAvatar(data) {
    var name = data.nickname ? data.nickname[0].toUpperCase() : data.username[0].toUpperCase()
    var username = '欢迎&nbsp;&nbsp;' + (data.nickname || data.username)
    // console.log(data.nickname || data.username);
    $("#user-name").html(username)
    console.log(name);
    if (data.user_pic === null) {
        $('.layui-nav-img').hide()
        $('.avatar').show().html(name)
    } else {
        $('.avatar').hide()
        $('.layui-nav-img').attr('src', data.user_pic)
    }
}
// 退出功能
$('#tuichu').on('click', function () {
    layer.confirm('确定退出吗？', { icon: 3, title: '提示' }, function (index) {
        //do something
        localStorage.removeItem('token')
        location.href = 'login.html'
        layer.close(index);
    });
})
// 强制退出
// function fQuit() {
//     if (!localStorage.getItem('token')) return location.href = 'login.html'
// }